#include <stdio.h>
#include <math.h>

int isPrime(int n)
{
	if (n==2 || n==3 || n==5 ||n==7)return 1;
	if (n%2 == 0 || n%3==0 || n==1)return 0;
	int i;
	for (i=5; i<=floor(sqrt(n)); i+=6) {
		if (n%i == 0 || n%(i+2)==0)return 0;
	}
	return 1;
}

int main()
{
	int i, i1, i2, i3, a[10]={0}, j;
	for (i=1489; i<3339; i+=2) {
		i1 = i;
		i2 = i1+3330;
		i3 = i2+3330;
		if (isPrime(i1) && isPrime(i2) && isPrime(i3)) {
			printf("%d%d%d\n", i1, i2, i3);
			while (i1) {
				a[i1%10]++;
				i1 /=10;
			}
			while (i2) {
				if(a[i2%10] == 0 || a[i3%10]==0)break;
				i2/=10;
				i3/=10;
			}
			if (i2 == 0) break;
			j = 0;
			while (j<10)a[j++]=0;
		}
	}
	printf("%d\n", i);
}

